package com.qfly.main.config;

import com.qfly.main.common.spring.QflyHandlerExceptionResolver;
import com.qfly.main.common.spring.ValidatorCollectionImpl;
import com.qfly.main.common.utils.JacksonUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.validation.Validator;
import org.springframework.validation.beanvalidation.SpringValidatorAdapter;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * Wisdytech.cn
 * com.qfly.main.config.WebMvcAutoConfiguration
 *
 * @author hailin.zhl
 * @date 2018/12/14
 */
@Configuration
public class WebMvcAutoConfiguration implements WebMvcConfigurer {

    @Override
    public Validator getValidator() {
        return new SpringValidatorAdapter(new ValidatorCollectionImpl());
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.forEach(JacksonUtils.wrapperObjectMapper());
    }

    @Override
    public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
        exceptionResolvers.add(new QflyHandlerExceptionResolver());
    }
}
